<template>
  <div>
    <van-sticky :offset-top="0">
      <van-nav-bar
        title="品牌制造商直供"
        left-text="返回"
        left-arrow
        @click-left="onClickLeft"
        @click-right="onClickRight"
      />
    </van-sticky>

    <!-- banner图片 -->
    <div class="top">
      <img class="banner" :src="data.pic_url" alt="" />
      <p class="title">{{ data.name }}</p>
      <div class="des">{{ data.simple_desc }}</div>
    </div>

    <div class="goods">
      <h4 v-if="show">数据库暂无数据...</h4>
      <div
        @click="togoodsinfo(item.id)"
        class="item"
        v-for="item in goodsList"
        :key="item.id"
      >
        <img :src="item.list_pic_url" alt="" />
        <h3>{{ item.name }}</h3>
        <p>{{ item.retail_price }}</p>
      </div>
    </div>
  </div>
</template>

<script>
import { index, goodsList, detailaction, listaction } from "@/api/home/index";

export default {
  components: {},

  data() {
    return {
      data: [],
      goodsList: [],
      show: false,
    };
  },

  created() {
    detailaction({ id: this.$route.params.id }).then((res) => {
      console.log(res);
      this.data = res.data;
      this.goodsList = res.goodsList;
      if (this.goodsList.length == 0) {
        this.show = true;
      }
    });
  },

  mounted() {},

  methods: {
    //到商品详细页
    togoodsinfo(goodsid) {
      console.log(goodsid);
      this.$router.push({
        name: "goodsinfo",
        params: {
          id: goodsid,
        },
      });
    },
    onClickLeft() {
      this.$router.go(-1)
    },
    onClickRight() {},
  },

  computed: {},

  watch: {},
};
</script>

<style scoped lang='less'>
.goods {
  width: 375px;
  display: flex;
  justify-content: space-between;
  flex-wrap: wrap;
  h4 {
    font-size: 18px;
    margin: 00px auto;
    margin-top: 160px;
    color: #999;
  }
  .item {
    width: 185px;
    margin-top: 5px;
    background-color: #fff;
    img {
      width: 151px;
    }
    h3 {
      margin: 5px auto;
    }
    p {
      color: red;
      margin-bottom: 20px;
    }
  }
}
.top {
  background-color: #fff;
  padding-bottom: 20px;
  .banner {
    width: 375px;
    height: 145px;
  }
  .title {
    font-size: 26px;
    width: 148px;
    margin: 0 auto;
    margin-top: -100px;
    color: white;
    border-bottom: 2px solid rgb(128, 59, 59);
  }
  .des {
    width: 335px;
    font-size: 14px;
    margin: 0 auto;
    margin-top: 80px;
    color: #999;
    letter-spacing: 1px;
    line-height: 16px;
  }
}
</style>